<?php
/**
 *
 * Author: Lyu
 * Date: 2023/7/22
 * Time: 17:50
 */

namespace App\OpenApi\AdminApi\Admin;

use App\Service\Core\Admin\Menu\AdminMenuService;
use App\Service\Core\Admin\Menu\AdminMenuStoreService;
use App\Service\Core\Admin\Power\AdminUserPowerService;
use App\Service\OpenApi\AdminApi\OpenBaseApi;

class AdminMenuApi extends OpenBaseApi
{
    /**
     * 获取列表
     * @return array
     */
    public function index(): array
    {
        $list = AdminMenuService::getMenuTreeList();
        return alert_info(0, 'Ok', $list);
    }

    public function power(): array
    {
        return AdminUserPowerService::getInstance()->getUserMenuList((int)$this->operate_id);
    }


    /**
     *
     * @return array
     * @throws \Throwable
     */
    public function delete(): array
    {
        return AdminMenuService::getInstance()->delete($this->input('ids'), $this->operate_id, $this->operate_by);
    }

    /**
     *
     * @return array
     * @throws \Throwable
     */
    public function draggingChange(): array
    {
        return AdminMenuService::getInstance()
            ->draggingChange(
                $this->input('dragging_id'),
                $this->input('drop_id'),
                $this->input('drop_type'),
                $this->operate_id,
                $this->operate_by);
    }

    public function store(): array
    {
        return (new AdminMenuStoreService())
            ->setName($this->input('name'))
            ->setParentId($this->input('parentId'))
            ->setPath($this->input('path'))
            ->setMeta($this->input('meta'))
            ->setComponent($this->input('component'))
            ->setRedirect($this->input('redirect'))
            ->setActive($this->input('active'))
            ->setOperate($this->operate_id, $this->operate_by)
            ->store($this->input('id'));
    }
}
